const axios = require('axios');
const fs = require('fs');

const imageUrl = './头像.jpg'; // 替换为你的图片路径
const token =  '72_CpGm2g61tz5bnVFtbMSSDQHKXHbv5bHRgYcZk6kGMg8aXqmoSAYHODxvRn6EEc8taV0n6a-wHk4ptV-Axe88Vcp2YB9S0N54u-1430aN5fEtpZMbbbdgd176rPMVRPcAAAHDB'
const uploadUrl = 'https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token' + token
async function uploadImage() {
  try {
    const imageStream = fs.createReadStream(imageUrl);
    const formData = new FormData();
    
    formData.append('file', imageStream);

    const response = await axios.post(uploadUrl, formData);

    if (response.status === 200) {
      console.log('Image uploaded successfully.', response.data);
    } else {
      console.log('Failed to upload image.');
    }
  } catch (error) {
    console.error('Error uploading image:', error.message);
  }
}

uploadImage();
